#include "stdio.h"
#include "../section_locate.h"

#include "pt-thread.h"

void pt_sem_test(void);

static char name[30] = "pt_sem_test";
struct func_pack sec_pt_sem_test __attribute__ ( ( section ( "func_area" ) ) ) = {
    .func_addr = pt_sem_test,
	.name_str = (uint32_t *)&name,
};



struct pt rcv_pt;
struct pt_sem sem_test;
static PT_THREAD( rcv_sem_entry(struct pt *pt) )
{
    int res;
    PT_BEGIN ( pt );

    while(1){
        printf("rcv_sem_entry\n\n");

        res = PT_SEM_WAIT_TO(&sem_test, 1000);

        if(res == 0){
            printf("rcv ok\n");
        }else{
            printf("rcv to\n");
        }
    }

    PT_END( pt );
}

struct pt send_pt;
static PT_THREAD( send_sem_entry(struct pt *pt) )
{

    PT_BEGIN ( pt );

    while(1){
        printf("send_sem_entry\n\n");
        PT_THREAD_MDELAY(2340);
		pt_sem_signal(&sem_test);

    }

    PT_END( pt );
}


void pt_sem_test(void)
{

	PT_SEM_INIT(&sem_test, 0);
	pt_thread_init(&rcv_pt, rcv_sem_entry);
	pt_thread_init(&send_pt, send_sem_entry);

}



